﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Workflow.Application.ErrorCode
{
    public class ApiResult<T>
    {
        /// <summary>
        /// 返回信息
        /// </summary>
        public string? Message { get; set; }
        /// <summary>
        /// 返回值
        /// </summary>
        public T? Data { get; set; }
        /// <summary>
        /// 返回状态
        /// </summary>
        public StateCodeEnum Code { get; set; }
        /// <summary>
        /// 返回成功的结果
        /// </summary>
        /// <param name="data"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static ApiResult<T> Success(T? data = default, string msg = "操作成功")
        {
            return new ApiResult<T> { Message = msg, Data = data, Code = StateCodeEnum.Ok };
        }
        /// <summary>
        /// 返回失败的结果
        /// </summary>
        /// <param name="data"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static ApiResult<T> Fail(string msg = "操作失败", T? data = default)
        {
            return new ApiResult<T> { Message = msg, Data = data, Code = StateCodeEnum.Fail };
        }
    }
}
